-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Active Message receiver callbacks #186
Add Active Message receiver callbacks #186
Conversation
@mdemoret-nv FYI |
Any non-const container that may have an external reference (such as a `std::string_view`) may change its underlying content and invalidate hashing, thus we must ensure the value can't change once registered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, I think
cpp/src/internal/request_am.cpp
Outdated
if (_receiverCallback) { | ||
_request->_callback = [this](ucs_status_t, std::shared_ptr<void>) { | ||
_receiverCallback(_request); | ||
}; | ||
} | ||
|
||
_request->callback(request, status); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make more sense to do this rewriting on the _request
in the constructor, rather than the callback? That way you wouldn't even need the _receiverCallback
slot I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 1542744
cpp/src/request_am.cpp
Outdated
|
||
memcpy(serialized.data() + offset, &memoryType, sizeof(memoryType)); | ||
offset += sizeof(memoryType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very minor polish, perhaps unnecessary:
auto encode = [&offset, &serialized](void const *data, size_t bytes) {
memcpy(serialized.data() + offset, data, bytes);
offset += bytes;
}
And then:
encode(&memoryType, sizeof(memoryType));
encode(&hasReceiverCallback, sizeof(hasReceiverCallback));
if (hasReceiveCallback) {
encode(&ownerSize, sizeof(ownerSize));
encode(receiverCallbackInfo->owner.c_str(), ownerSize);
encode(&receiverCallbackInfo->id, sizeof(receiverCallbackInfo->id));
}
And something matching on the decode side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's an excellent idea! Done in 1920ff1 .
cpp/src/request_am.cpp
Outdated
auto allocatorType = *static_cast<const ucs_memory_type_t*>(header); | ||
// auto amHeader = AmHeader::deserialize(static_cast<const char*>(header)); | ||
auto amHeader = | ||
AmHeader::deserialize(std::string(static_cast<const char*>(header), header_length)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This copies the header, suggestion:
AmHeader::deserialize(std::string(static_cast<const char*>(header), header_length)); | |
AmHeader::deserialize(std::string_view(static_cast<const char*>(header), header_length)); |
And accept a std::string_view
in deserialize
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 4304378 .
Thanks @wence- for reviewing! |
/merge |
Adds a new pattern to receive Active Messages where the receiving endpoint registers a callback and the sender informs receiver of the callback to use, the receiver then executes that callback and does not require an explicit
ep->amRecv()
call.Sample code:
This PR only implements C++ parts, #187 tracks the missing Python implementation.